using System;
using System.Collections.Generic;
using System.Text;

namespace PersistenceObject.Framework.Expressions
{
    public class BooleanField : FieldAdapter
    {
        public BooleanField(string name)
            : base(name)
        {
        }

        public BooleanField(string name, FieldAdapter basefield)
            : base(name, basefield)
        {
        }

        public BooleanField As(string name)
        {
            return new BooleanField(string.Format("{0} {1}", this.Name, name), this);
        }

        public BooleanField At(Table table)
        {
            String[] tempArr = this.Name.Split('.');
            if (tempArr.Length > 1)
            {
                this.name = tempArr[1];
            }

            string alias = table.Alias;
            if (string.IsNullOrEmpty(alias))
            {
                alias = table.Name;
            }
            return new BooleanField(string.Format("{0}.{1}", alias, this.Name), this);
        }

        public static Expression operator ==(BooleanField field, bool value)
        {
            return Expressions.Equals(field.Name, value);
        }

        public static Expression operator !=(BooleanField field, bool value)
        {
            return Expressions.NotEquals(field.Name, value);
        }

        public FieldValue Set(bool value)
        {
            return new FieldValue(this.Name, value);
        }
    }
}
